<template>
  <!-- 古代现存的桥梁 -->
  <div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="78px"
    >
      <el-form-item label="桥梁编号" prop="bridgeNum">
        <el-input
          v-model="queryParams.bridgeNum"
          placeholder="请输入桥梁编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="桥梁名称" prop="bridgeName">
        <el-input
          v-model="queryParams.bridgeName"
          placeholder="请输入桥梁名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属市区" prop="province">
        <el-cascader
          :options="regionData"
          v-model="selectedOptions"
          @change="handleChange"
          style="width: 320px"
          placeholder="请选择省市区"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="古今桥梁" prop="bridgeAge">
        <el-select
          v-model="queryParams.bridgeAge"
          placeholder="请选择桥梁年代"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_bridge_age"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发布状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择发布状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.publish_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:list:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:list:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:list:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:list:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-arrow-left"
          :disabled="multiple"
          size="mini"
          @click="handleWithdraw"
          v-hasPermi="['system:list:edit']"
          >撤回</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="listList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="桥梁编号"
        align="center"
        prop="bridgeNum"
        width="120"
      />
      <el-table-column
        label="桥梁名称"
        align="center"
        prop="bridgeName"
        width="180"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span style="color: red" v-if="scope.row.isTop == '1'">[顶] </span>
          <span style="color: red" v-if="scope.row.isBottom == '1'">[底] </span>
          <span>{{ scope.row.bridgeName }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="营建年代"
        align="center"
        prop="constructYear"
        :width="120"
      />
      <el-table-column label="所属地区" align="center" prop="lat" :width="190">
        <template slot-scope="scope">
          {{ scope.row.province }} {{ scope.row.city }} {{ scope.row.city }}
        </template>
      </el-table-column>
      <el-table-column label="位置" align="center" prop="address">
      </el-table-column>
      <el-table-column
        label="跨域障碍类型"
        align="center"
        prop="obstacleType"
        width="130"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.obstacle_type"
            :value="scope.row.obstacleType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="保护级别"
        align="center"
        prop="protectionLevel"
        width="160"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_protection_level"
            :value="scope.row.protectionLevel"
          />
        </template>
      </el-table-column>
      <el-table-column label="材质" align="center" prop="material">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_material"
            :value="scope.row.material"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="古代桥梁类型"
        align="center"
        prop="oldBridgeType"
        width="130"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_old_bridge_type"
            :value="scope.row.oldBridgeType"
          />
        </template>
      </el-table-column>
      <el-table-column label="桥梁全长" align="center" prop="bridgeLength">
      </el-table-column>
      <el-table-column label="桥梁中宽" align="center" prop="bridgeWidth">
      </el-table-column>
      <el-table-column label="桥梁净跨" align="center" prop="bridgeSpan">
      </el-table-column>
      <el-table-column label="孔数" align="center" prop="bridgeHoles">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            style="width: 32px"
            type="primary"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:list:edit']"
            >修改</el-button
          >
          <el-tooltip
            class="item"
            effect="light"
            content="上移"
            placement="top"
          >
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-top"
              @click="moveUpOrDown(scope.row, 'up')"
              v-hasPermi="['system:list:remove']"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="下移"
            placement="top"
          >
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-bottom"
              @click="moveUpOrDown(scope.row, 'down')"
              v-hasPermi="['system:list:remove']"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            :content="scope.row.isTop != '1' ? '置顶' : '取消置顶'"
            placement="top"
          >
            <!-- <el-button
              size="mini"
              type="primary"
              icon="el-icon-upload2"
              @click="pinToTopOrEnd(scope.row, 'top')"
              v-hasPermi="['system:list:remove']"
            ></el-button> -->
            <el-button
              size="mini"
              type="primary"
              :icon="
                scope.row.isTop != '1'
                  ? 'el-icon-upload2'
                  : 'el-icon-refresh-left'
              "
              @click="pinToTopOrEnd(scope.row, 'top')"
              v-hasPermi="['system:list:remove']"
            ></el-button>
          </el-tooltip>

          <el-tooltip
            class="item"
            effect="light"
            :content="scope.row.isBottom != '1' ? '置底' : '取消置底'"
            placement="top"
          >
            <!-- <el-button
              size="mini"
              type="primary"
              icon="el-icon-download"
              @click="pinToTopOrEnd(scope.row, 'end')"
              v-hasPermi="['system:list:remove']"
            ></el-button> -->
            <el-button
              size="mini"
              type="primary"
              :icon="
                scope.row.isBottom != '1'
                  ? 'el-icon-download'
                  : 'el-icon-refresh-left'
              "
              @click="pinToTopOrEnd(scope.row, 'end')"
              v-hasPermi="['system:list:remove']"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="删除"
            placement="top"
          >
            <el-button
              size="mini"
              style="width: 22px"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:list:remove']"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      style="height: 90px"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listList,
  delList,
  addList,
  updateList,
  withdrawList,
  moveUpOrDown,
  pinToTopOrEnd,
} from "@/api/bussiness/list";
import { regionData, codeToText } from "element-china-area-data";
export default {
  name: "GdXS",
  dicts: [
    "sys_bridge_age",
    "publish_status",
    "obstacle_type",
    "sys_protection_level",
    "sys_old_bridge_type",
    "sys_material",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      codes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      regionData,
      codeToText,
      selectedOptions: [],
      // 总条数
      total: 0,
      // 清单表格数据
      listList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bridgeType: "GDXC",
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询清单列表 */
    getList() {
      this.loading = true;
      listList(this.queryParams).then((response) => {
        this.listList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        checkListId: null,
        bridgeNum: null,
        bridgeName: null,
        lng: null,
        lat: null,
        province: null,
        city: null,
        county: null,
        bridgeAge: null,
        bridgeDesc: null,
        bridgeContent: null,
        status: null,
        orderNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = this.$options.data().queryParams;
      this.selectedOptions = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.checkListId);
      this.codes = selection.map((item) => item.bridgeNum);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset()
      // this.open = true
      // this.title = '添加清单'
      this.$router.push({
        path: "gdxcAddList",
        query: { bridgeType: "GDXC", bridgeTypeName: "古代现存" },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset()
      const checkListId = row.checkListId || this.ids;
      // getList(checkListId).then((response) => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '修改清单'
      // })
      this.$router.push({
        path: "gdxcEditList",
        query: {
          checkListId: checkListId,
          bridgeType: "GDXC",
          bridgeTypeName: "古代现存",
        },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.checkListId != null) {
            updateList(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addList(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const checkListIds = row.checkListId || this.ids;
      const checkBridgeNums = row.bridgeNum || this.codes;
      this.$modal
        .confirm('是否确认删除清单编号为"' + checkBridgeNums + '"的数据项？')
        .then(function () {
          return delList(checkListIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/list/export",
        {
          ...this.queryParams,
        },
        `list_${new Date().getTime()}.xlsx`
      );
    },
    handleChange(value) {
      if (this.selectedOptions && this.selectedOptions.length >= 3) {
        this.queryParams.province = this.codeToText[this.selectedOptions[0]];
        this.queryParams.city = this.codeToText[this.selectedOptions[1]];
        this.queryParams.county = this.codeToText[this.selectedOptions[2]];
      }
    },
    handleWithdraw(row) {
      const checkListIds = row.checkListId || this.ids;
      const checkBridgeNums = row.bridgeNum || this.codes;

      this.$modal
        .confirm('是否确认撤回清单编号为"' + checkBridgeNums + '"的数据项？')
        .then(function () {
          return withdrawList(checkListIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("撤回成功");
        })
        .catch(() => {});
    },
    async moveUpOrDown(row, type) {
      let res = await moveUpOrDown({
        checkListId: row.checkListId,
        moveType: type,
      });
      if (res.code == 200) {
        this.getList();
        this.$modal.msgSuccess("移动成功");
      }
    },
    async pinToTopOrEnd(row, type) {
      let res = await pinToTopOrEnd({
        checkListId: row.checkListId,
        pinType: type,
      });
      if (res.code == 200) {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
